<script setup lang="ts">
import type { ElForm } from 'element-plus'
import { reactive, ref } from 'vue'

const searchForm = reactive({
  name: '',
  leader: '',
  createAt: ''
})
const useSearchFormRef = ref<InstanceType<typeof ElForm>>()
// 重置操作
const resetFormBtnClick = () => {
  useSearchFormRef.value?.resetFields()
  emit('resetClick')
}
// 搜索
const searchFormBtnClick = () => {
  emit('searchClick', searchForm)
}
// 自定义事件
const emit = defineEmits(['resetClick', 'searchClick'])
</script>
<template>
  <div class="search">
    <!-- 用户名 真实姓名 手机号码 状态 创建时间 重置 查询 -->
    <el-form label-width="100px" :model="searchForm" ref="useSearchFormRef">
      <el-row>
        <el-col :span="8">
          <el-form-item label="部门名称" prop="name">
            <el-input
              placeholder="请输入查询的用户名"
              v-model="searchForm.name"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="部门领导" prop="leader">
            <el-input
              placeholder="请输入查询的用户名"
              v-model="searchForm.leader"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="创建时间" prop="createAt">
            <el-date-picker
              v-model="searchForm.createAt"
              type="daterange"
              range-separator="-"
              start-placeholder="开始时间"
              end-placeholder="结束时间"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- btn -->
    <div class="btnbox">
      <div class="btn-item">
        <el-button type="primary" plain @click="resetFormBtnClick">
          <el-icon><Refresh /></el-icon>
          重置
        </el-button>
      </div>
      <div class="btn-item">
        <el-button type="primary" @click="searchFormBtnClick">
          <el-icon><Search /></el-icon>
          搜索
        </el-button>
      </div>
    </div>
  </div>
</template>
<style scoped lang="less">
.search {
  padding: 20px;
  border-radius: 10px;
  background-color: #ffffff;
  .el-form-item {
    margin: 18px 0;
  }
  .el-select {
    width: 100%;
  }
  .btnbox {
    display: flex;
    justify-content: right;
    align-items: center;
    .btn-item {
      margin: 0 15px;
      .el-button {
        .el-icon {
          margin-right: 5px;
        }
      }
    }
  }
}
</style>
